package operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOPeration {
    public void work(BookList bookList) {
        System.out.println("归还图书");
        Scanner in = new Scanner(System.in);
        System.out.println("请输入归还图书的名字");
        String name = in.nextLine();
        boolean flag = true;//默认是没有找到
        for (int i = 0; i < bookList.getUseSize(); i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                if(!bookList.getBook(i).isBorrowed()) {//表示还没借出
                    flag = false;
                    continue;
                }
                bookList.getBook(i).setBorrowed(false);
                System.out.println("成功归还此书，欢迎下次再来");
                return;
            }
        }
        if(flag){
            System.out.println("未找到这一本书，请重新核对一下书的名称");
        } else {
            System.out.println("您归还的书都是尚未借出，请联系图书管理员");
        }
    }
}
